package com.maxmlr.base.jvm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName Test3
 * @Description TODO
 * @Author maxiao
 * @Date 2020/3/26 下午2:36
 * @Version V1.0
 */
public class Test3 {

    public static void main(String[] args) {
        Integer[] arrayOld = new Integer[] {2,4, 5, 6, 7};
        Integer num = 15;
        boolean isContains = Arrays.asList(arrayOld).contains(num);
        Integer[] newArray = null;
        ArrayList<Object> arrayListnew = new ArrayList<>();
        List<Integer> resultList = new ArrayList<>(arrayOld.length);
        Collections.addAll(resultList,arrayOld);
        arrayListnew.add(num);
        if(isContains){
            resultList.remove(resultList.indexOf(num));
            arrayListnew.addAll(resultList);
        }else{
            arrayListnew.addAll(resultList);
        }
        newArray=arrayListnew.toArray(new Integer[arrayListnew.size()]);

        System.out.println(isContains);
        System.out.println(Arrays.toString(arrayOld));
        //arrayOld = newArray;
        System.out.println(Arrays.toString(newArray));
    }
}
